package org.gpp.proj1.camera.action;

import junit.framework.TestCase;

import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.scene.CameraNode;
import com.jme.system.DisplaySystem;

public class MoveToPointActionTest extends TestCase {

	/*
	 * Test method for 'org.gpp.proj1.camera.action.MoveToPointAction.MoveToPointAction(CameraNode, Vector3f, float)'
	 */
	public void testMoveToPointAction() {
		// Cannot create action with null cam node
		try {
			new MoveToPointAction( null, null, 0.0f );
			fail();
		} catch( AssertionError e ) {
			// Expected error
		}
		
		// Cannot create action with null cam node
		Camera cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();		
		CameraNode node = new CameraNode( "CamNode", cam );
		
		try {
			new MoveToPointAction( node, null, 0.0f );
			fail();
		} catch( AssertionError e ) {
			// Expected error
		}
		
		// Cannot create action with negative duration
		try {
			new MoveToPointAction( node, new Vector3f( 0, 0, 0 ), -1.0f );
			fail();
		} catch( AssertionError e ) {
			// Expected error
		}

		// Valid construct
		try {
			new MoveToPointAction( node, new Vector3f( 0, 0, 0 ), 1.0f );
		} catch( AssertionError e ) {
			fail();
		}
	}

	/*
	 * Test method for 'org.gpp.proj1.camera.action.MoveToPointAction.updateAction(float, CameraNode)'
	 */
	public void testUpdateAction() {
		Camera cam = DisplaySystem.getDisplaySystem().getRenderer().createCamera( 0, 0 );		
		CameraNode node = new CameraNode( "CamNode", cam );
		
		node.setLocalTranslation( new Vector3f( 0, 0, 0 ) );
		
		MoveToPointAction action = new MoveToPointAction( node, new Vector3f( 1, 1, 1 ), 1.0f );
		
		action.updateAction( 1.0f, node );
		
		assertTrue( action.isFinished() );
		
		assertEquals( new Vector3f( 1, 1, 1 ), node.getLocalTranslation() );
	}

	/*
	 * Test method for 'org.gpp.proj1.camera.action.MoveToPointAction.isFinished()'
	 */
	public void testIsFinished() {
		Camera cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();		
		CameraNode node = new CameraNode( "CamNode", cam );
		
		MoveToPointAction action = new MoveToPointAction( node, new Vector3f( 0, 0, 0 ), 1.0f );
		action.updateAction(  1.0f, node );
		
		assertTrue( action.isFinished() );
	}

}
